# coding:utf-8
import asyncio
import os
import random
import gevent


async def a():
    for i in range(10):
        print(i, 'a', os.getpid())
        # time.sleep是cpu级别的阻塞，这个异步也是无法做到的
        # time.sleep(random.random() * 2)
        await asyncio.sleep(random.random() * 2)
    return 'a function'


async def b():
    for i in range(10):
        print(i, 'b', os.getpid())
        # time.sleep(random.random() * 2)
        await asyncio.sleep(random.random() * 2)
    return 'b function'


def gevent_a():
    for i in range(10):
        print(i, 'a gevent', os.getpid())
        gevent.sleep(random.random() * 2)
    return 'gevent a result'


def gevent_b():
    for i in range(10):
        print(i, 'b gevent', os.getpid())
        gevent.sleep(random.random() * 2)
    return 'gevent b result'


async def main():
    result = await asyncio.gather(a(), b())
    print(gevent)
    print(result)


if __name__ == '__main__':
    # asyncio.run(main=main())
    g_a = gevent.spawn(gevent_a)
    g_b = gevent.spawn(gevent_b)
    gevent_list = [g_a, g_b]
    result = gevent.joinall(gevent_list)
    print(result[0].value,result[1].value)
